package com.easyfun.healthmagicbox.sqllite;

import com.easyfun.healthmagicbox.R;
import com.easyfun.healthmagicbox.auth.LoginActivity;
import com.easyfun.healthmagicbox.base.DatabaseAccess;
import com.easyfun.healthmagicbox.base.DatabaseAccessImplementation;
import com.easyfun.healthmagicbox.ormlite.DatabaseHelper;

import android.content.Context;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivityTestCase extends  
		ActivityInstrumentationTestCase2<LoginActivity> implements DatabaseAccess{

	private final static String TAG = LoginActivityTestCase.class.getSimpleName();
	 // MainActivity是需要单元测试的android的activity
    private LoginActivity mActivity;
    
    // TextView是Activity中的一个组件
    private EditText mEditUsername;
    private EditText mEditPassword;
	private String resourceString;
	private Button mLoginButton;
    
	public LoginActivityTestCase(Class<LoginActivity> activityClass) {
		super(activityClass);
	}
	
	@Override  
    protected void setUp() throws Exception {  
        super.setUp();  
        mActivity = this.getActivity();
        mEditUsername = (EditText) mActivity.findViewById(R.id.page1_login_user_edit);
        mEditPassword = (EditText) mActivity.findViewById(R.id.page1_login_passwd_edit);
        
        mLoginButton = (Button) mActivity.findViewById(R.id.page1_login_but);
        //resourceString = mActivity.getString(R.string.hello);
        getHelper(mActivity).clearDatabase();	
    } 
	
	// 单元测试的内容
    public void testPreconditions() {
    	//断言
         assertNotNull(mEditUsername);
         assertNotNull(mEditPassword);
    }

    public void testLogin() {
    	getHelper(mActivity).clearDatabase();
    	String username ="";
    	String password ="";
    	mEditUsername.setText(username);
    	mEditPassword.setText(password);
    	mLoginButton.performClick();
    	
        //assertEquals(resourceString, (String) mView.getText());
    }
    
    @Override
	public DatabaseHelper getHelper(Context context) {
		return DatabaseAccessImplementation.getInstance().getHelper(context);
	}
}
